package com.mzy.linear_struct.hot100.栈;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: mizy3
 * @Date: 2024/09/04/下午8:33
 * @Description:
 */
public class Pro1两数之和 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        // nums = [2,7,11,15], target = 9
        for (int i = 0; i < nums.length; i++) {
            int n = target - nums[i];
            if (map.containsKey(nums[i])) {
                return new int[]{map.get(nums[i]), i};
            }
            map.put(n, i);
        }

        return new int[]{-1, -1};
    }
}






















